package com.jf.basic.juc.aqs;

import java.util.concurrent.atomic.AtomicInteger;

import static java.lang.System.out;

/**
 * Volatile Test
 *
 * @author Junfeng
 */
public class VolatileTest {

    private AtomicInteger num = new AtomicInteger();

    public void addPlusPlus() {
        num.getAndIncrement();
    }

    public static void main(String[] arg) {

        final VolatileTest test = new VolatileTest();

        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    test.addPlusPlus();
                }
            }, String.valueOf(i)).start();
        }


        while (Thread.activeCount() > 2) {
            Thread.yield();
        }

        out.println(" -[DEBUG]-   " + test.num.get());
    }
}
